package 初级算法;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

public class 求最大子集 {
    volatile static Boolean f = false;

    static AtomicInteger in = new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException {
        int[] is = new int[]{-2,1,-3,4,-1,2,1,-5,4};
        System.out.println(maxSubArray(is));
    }

    public static int maxSubArray(int[] nums) {
        int max = nums[0];
        int[] is = new int[nums.length];
        is[0] =max;
        for (int i = 1; i < nums.length; i++) {
            is[i]=Math.max(is[i-1],0)+nums[i];
            max=Math.max(max,is[i]);
        }
        return max;
    }
}